/********************************************************************
 * Copyright(c) 2023-2023 Grayson Zheng.
 * File: uart.h
 * Description: Header file of AT89C52 serial port communication.
 * Version: 1.1
 * Date: 2023-12-14
 * Author: zhengxinyu13@qq.com
 * ---------- Revision History ----------
 * <version>
 * <date>
 * <author>
 * <desc>
 * Modified to be suitable to the new coding rules in all functions.
 ********************************************************************/

#include <stdio.h>
#include "regx52.h"
#include "datatype.h"
#include "bit.h"

#ifndef __UART_H__
#define __UART_H__

/* System frequency */
#define FOSC_1 11059200UL		//The crystal frequency is 11.0592MHz.
#define FOSC_2 12000000UL		//The crystal frequency is 12.00MHz.

/* System clock */
#define _1T_MODEL 1			//No frequency division mode.
#define _12T_MODEL 12		//12 frequency division mode.

#define SYSCLK 32

/*Define UART parity mode*/
#define NONE_PARITY		0	//None parity
#define ODD_PARITY		1	//Odd parity
#define EVEN_PARITY 	2	//Even parity
#define MARK_PARITY		3	//Mark parity
#define SPACE_PARITY	4	//Space parity

#define PARITYBIT NONE_PARITY	//Testing even parity.

/* List of baud rates */
#define BAUD_RATE_1200	1200
#define BAUD_RATE_2400	2400
#define BAUD_RATE_4800	4800
#define BAUD_RATE_9600	9600
#define BAUD_RATE_19200	19200

#define END_MARK '`'	//User defined.

typedef struct
{
	uint_8 buff[64];
	uint_8 flag;
	uint_8 len;
}REC;
 
extern REC UART_rec;

void uart_init(uint_16 baudrate);
void send_byte(int_8 data_msg);
void send_msg(int_8 *data_msg);

#endif
